# import time
# import threading

# def worker():
# print('worker')
# time.sleep(2)

# threads = []

# if __name__ == '__main__':
# 	for i in range(5):
# 		t = threading.Thread(target=worker)
# 		threads.append(t)
# 		t.start()

# for item in threading.enumerate():
# 	print(item)

# print('=' * 10)

# for item in threads:
# 	print(item)

# print('current has %d threads' % (threading.activeCount() - 1))


# import urllib2
# import time

# hosts = ["http://www.baidu.com/", "http://www.21cp.com/", 'http://zhidao.baidu.com/', 
# 		 "http://www.baidu.com/", "http://www.21cp.com/", 'http://zhidao.baidu.com/']

# start = time.time()
# #grabs urls of hosts and prints first 1024 bytes of page
# for host in hosts:
# 	url = urllib2.urlopen(host)
# 	print url.read(1024)

# print "Elapsed Time: %s" % (time.time() - start)



# """A basic fork in action"""

# import os

# def my_fork():
#     child_pid = os.fork()
#     if child_pid == 0:
#         print "Child Process: PID# %s" % os.getpid()
#     else:
#         print "Parent Process: PID# %s" % os.getpid()

# if __name__ == "__main__":
#     my_fork()



from multiprocessing import Process
import os
import time


def sleeper(name, seconds):
    print 'starting child process with id: ', os.getpid()
    print 'parent process:', os.getppid()
    print 'sleeping for %s ' % seconds
    time.sleep(seconds)
    print "Done sleeping"


if __name__ == '__main__':
    print "in parent process (id %s)" % os.getpid()
    p = Process(target=sleeper, args=('bob', 5))
    p.start()
    print "in parent process after child process start"
    print "parent process about to join child process"
    # p.join()
    print "in parent process after child process join"
    print "parent process exiting with id ", os.getpid()
    print "The parent's parent process:", os.getppid()
